package com.pzb.web.controller.market;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.pzb.common.annotation.Log;
import com.pzb.common.core.controller.BaseController;
import com.pzb.common.core.domain.AjaxResult;
import com.pzb.common.enums.BusinessType;
import com.pzb.market.domain.MkGroupbuyingGoods;
import com.pzb.market.service.IMkGroupbuyingGoodsService;
import com.pzb.common.core.page.TableDataInfo;

/**
 * 拼购商品Controller
 * 
 * @author Mr_Wu
 * @date 2021-12-22
 */
@RestController
@RequestMapping("/market/groupGoods")
public class MkGroupbuyingGoodsController extends BaseController
{
    @Autowired
    private IMkGroupbuyingGoodsService mkGroupbuyingGoodsService;

    /**
     * 查询拼购商品列表
     */
    @GetMapping("/list")
    public TableDataInfo list(MkGroupbuyingGoods mkGroupbuyingGoods)
    {
        startPage();
        List<MkGroupbuyingGoods> list = mkGroupbuyingGoodsService.selectMkGroupbuyingGoodsList(mkGroupbuyingGoods);
        return getDataTable(list);
    }

    /**
     * 获取拼购商品详细信息
     */

    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(mkGroupbuyingGoodsService.selectMkGroupbuyingGoodsById(id));
    }

    /**
     * 获取拼购商品详细信息
     */

    @GetMapping(value = "/{groupId}")
    public AjaxResult getGroupGoodsByGroupId(@PathVariable("groupId") Long groupId)
    {
        MkGroupbuyingGoods q =new MkGroupbuyingGoods();
        q.setGroupId(groupId);
        q.setIsShow("0");
        List<MkGroupbuyingGoods> list = mkGroupbuyingGoodsService.selectMkGroupbuyingGoodsList(q);
        return AjaxResult.success(list);
    }

    /**
     * 新增拼购商品
     */
    @Log(title = "拼购商品", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody List<MkGroupbuyingGoods> groupbuyGoodsList)
    {
        return toAjax(mkGroupbuyingGoodsService.insertMkGroupbuyingGoods(groupbuyGoodsList));
    }

    /**
     * 修改拼购商品
     */
    @Log(title = "拼购商品", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody MkGroupbuyingGoods mkGroupbuyingGoods)
    {
        return toAjax(mkGroupbuyingGoodsService.updateMkGroupbuyingGoods(mkGroupbuyingGoods));
    }

    /**
     * 删除拼购商品
     */
    @Log(title = "拼购商品", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(mkGroupbuyingGoodsService.deleteMkGroupbuyingGoodsByIds(ids));
    }

    /**
     * 上移商品
     */
    @Log(title = "拼购商品", businessType = BusinessType.UPDATE)
    @PostMapping("/moveUpGoods")
    public AjaxResult moveUpGoods(@RequestBody MkGroupbuyingGoods mkGroupbuyingGoods)
    {
        return toAjax(mkGroupbuyingGoodsService.moveUpGoods(mkGroupbuyingGoods ));
    }
    /**
     * 下移商品
     */
    @Log(title = "拼购商品", businessType = BusinessType.UPDATE)
    @PostMapping("/moveDownGoods")
    public AjaxResult moveDownGoods(@RequestBody MkGroupbuyingGoods mkGroupbuyingGoods)
    {
        return toAjax(mkGroupbuyingGoodsService.moveDownGoods(mkGroupbuyingGoods));
    }

    /**
     * 状态修改
     */
    @Log(title = "拼购商品", businessType = BusinessType.UPDATE)
    @PostMapping("/changeStatus")
    public AjaxResult changeStatus(@RequestBody MkGroupbuyingGoods mkGroupbuyingGoods)
    {
        return toAjax(mkGroupbuyingGoodsService.updateMkGroupbuyingGoods(mkGroupbuyingGoods));
    }
}
